import Blockly from 'blockly/core'
import 'blockly/python_compressed'
import 'blockly/blockly_compressed'
import 'blockly/blocks_compressed'

// 实现print模块
Blockly.Blocks.print_function = {
  init: function () {
    this.appendValueInput('SETENCE').setCheck(null).appendField('print')
    this.setInputsInline(true)
    this.setPreviousStatement(true, null)
    this.setNextStatement(true, null)
    this.setColour(75)
    this.setTooltip('打印语句')
    this.setHelpUrl('')
  }
}

// 模块代码
Blockly.Python.print_function = function (block) {
  const setence = Blockly.Python.valueToCode(
    block,
    'SETENCE',
    Blockly.Python.ORDER_NONE
  )
  let code = ''
  code = 'print(' + setence + ')\n'
  return code
}

// 实现return模块，为上下可接管
Blockly.Blocks.return = {
  init: function () {
    this.appendValueInput('SETENCE').setCheck(null).appendField('return ')
    this.setInputsInline(true)
    this.setPreviousStatement(true, null)
    this.setNextStatement(true, null)
    this.setColour(75)
    this.setTooltip('返回')
    this.setHelpUrl('')
  }
}

Blockly.Python.return = function (block) {
  const setence = Blockly.Python.valueToCode(
    block,
    'SETENCE',
    Blockly.Python.ORDER_NONE
  )
  let code = ''
  code = 'return ' + setence + '\n'
  return code
}

Blockly.Blocks.returnnull = {
  init: function () {
    this.appendDummyInput().appendField('return')
    this.setInputsInline(true)
    this.setPreviousStatement(true, null)
    this.setNextStatement(true, null)
    this.setColour(75)
    this.setTooltip('返回')
    this.setHelpUrl('')
  }
}

Blockly.Python.returnnull = function (block) {
  let code
  // eslint-disable-next-line prefer-const
  code = 'return\n'
  return code
}

export default Blockly
